#include "Dictionary.h"

Dictionary::Dictionary():storer()
{
}

Dictionary::~Dictionary()
{
	for (pStorDictIter it = storer.begin(); it != storer.end(); ++it)
	{
		delete it->second;
	}
}

void Dictionary::add(INumberAndWord* pNum)
{
	if ( isEmpty() )
	{
		storer.insert( make_pair( pNum->getRank(), pNum ) );
		return;
	}

	BasicSearch _search1 = BasicSearch( pNum->getValue() );
	if ( !searchValue<BasicSearch>(pNum->getValue(), pNum->getRank(), &_search1) ) 
	{
		storer.insert( make_pair( pNum->getRank(), pNum ) );
	}
}
bool Dictionary::isBaseValue(long pValue)
{	
	for (pStorDictIter it = storer.begin(); it != storer.end(); ++it)
	{
		if ( ( pValue == it->second->getValue() ) && ( it->second->getType() == 1 ) )
		{
			return true;
		}
	}
	return false;
}
int Dictionary::countValue(long pValue, int pRank)
{
	return storer.count(pValue);
}
bool Dictionary::isEmpty()
{
	return storer.empty();
}

int Dictionary::size()
{
	return storer.size();
}